%{


	/*definições das constantes manifestas
	LT,LE,EQ,NE,GT,GE
	IF,THEN,ELSE,ID,NUMERO,RELOP */
	
	#define LT 1
	#define LE 2
	#define EQ 3
	#define NE 4
	#define GT 5
	#define GE 6

	#define MOD 62
	#define MULT 60
	#define DIV 61
	#define EE 66
	#define OU 67
	#define VIRGULA 53
	#define STEP 24 

	
/*	#define IF 7	
	#define THEN 8
	#define ELSE 9
	#define ID 10
	#define NUMERO 11
	#define RELOP 12
	#define VAR 13
	#define CONST 14
	#define TYPE 15
	#define PROGRAM 16
	#define INICIO 17
	#define FIM 18
	#define FOR 19
	#define WHILE 20
	#define DO 21
	#define TO 22
	#define DOWNTO 23

	#define REPEAT 25
	#define UNTIL 26
	#define CASE 27
	#define FUNCTION 28
	#define PROCEDURE 29
	#define ASPECT 30
	#define BEFORE 31
	#define AFTER 32
	#define WRITELN 33
	#define READLN 34
	#define RECORD 35
	#define ARRAY 36
	#define RANGE 37
	#define TRUE 38
	#define FALSE 39
	#define BOOLEAN 40
	#define REAL 41
	#define INTEGER 42
	#define STRING_TYPE 43
	#define CHAR_TYPE 44
	#define STRING_TERM 45
	#define CHAR_TERM 46
	#define OP_ARITMETICO 49
	#define ATRIBUICAO 50
	#define DOISPONTOS 51
	#define PONTO 52
	#define PONTOEVIRGULA 54
	#define ABRECOL 55
	#define FECHACOL 56
	#define ABREPAR 57
	#define FECHAPAR 58
	#define MAIS 59

	#define MENOS 63 
	#define NAO 64
	#define OP_LOGICO 65
	
	#define POINTER 68
	#define FLOAT 69
	#define OF 70
	#define CONST_ATRIB 71

	#define DBG 1
	
*/


	//int yylval = 0;
	//{pointerDec}	{printf(" pointer dec ");yylval = instalar_id();return (POINTER_DEC);}
	//{pointerVar}	{printf(" pointer var ");yylval = instalar_id();return (POINTER_VAR);}
	//writeln		{printf(" WRITELN ");return (WRITELN);}
	//readln		{printf(" READLN ");return (READLN);}

no instalar_id();
no instalar_float();
no instalar_numero();
no instalar_char();
no instalar_string();

%}

/* definições regulares */
delim	[ \t]
ws	{delim}+
letra	[A-Za-z]
digito  [0-9]
espechar ("."|","|";"|"("|"*"|"!"|"~"|"@"|"#"|"$"|"%"|"^"|"&"|"*"|"("|")"|"-"|"_"|"+"|"="|"`"|"{"|"}"|"["|"]"|"|"|":"|"<"|">"|"?"|"/")
id	{letra}({letra}|{digito})*
float	[\-]?{digito}+(\.{digito}+)(E[+\-]?{digito}+)?
numero  [\-]?{digito}*
string  	\"({delim}|{letra}|{digito}|{espechar})*\"
char		\'({delim}|{letra}|{digito}|{espechar})\'
pointerDec 	\^{id}
pointerVar 	{id}\^

%Start comment0 comment1

%%

<INITIAL>"/*"			{ BEGIN(comment0); }
<comment0>\*			{ BEGIN(comment1); }
<comment0>[\n]			{++linha;}
<comment0>.			{;}
<comment1>\*			{;}
<comment1>\/			{ BEGIN(INITIAL); }
<comment1>.			{ BEGIN(comment0); }


	<INITIAL>[\n]		{++linha;}
	<INITIAL>{ws}		{/*nenhuma ação e nenhum valor retornado */}
	<INITIAL>var		{	
					#if DBG == 1
						printf(" VAR ");
				 	#endif
					return (VAR);
				}
	<INITIAL>const		{
					#if DBG == 1
						printf(" CONST ");
					#endif
                    yylval = criarNovoNoBasico(" const ", 0);
					return (CONST);
				}
	<INITIAL>program	{
					#if DBG == 1
						printf(" PROGRAM ");
					#endif
					return (PROGRAM);
				}
	<INITIAL>repeat		{
					#if DBG == 1
						printf(" REPEAT ");
					#endif
					return (REPEAT);
				}
	<INITIAL>until		{
					#if DBG == 1
						printf(" UNTIL ");
					#endif
					return (UNTIL);
				}
	<INITIAL>type		{
					#if DBG == 1
						printf(" TYPE ");
					#endif
					return (TYPE);
				}
	<INITIAL>if		{
					#if DBG == 1
						printf(" IF ");
					#endif
					return (IF);
				}
	<INITIAL>then		{
					#if DBG == 1
						printf(" THEN ");
					#endif
					return (THEN);
				}
	<INITIAL>else		{
					#if DBG == 1
						printf(" ELSE ");
					#endif
					return (ELSE);
				}
	<INITIAL>for		{
					#if DBG == 1
						printf(" FOR ");
					#endif
					return (FOR);
				}
	<INITIAL>while		{
					#if DBG == 1
						printf(" WHILE ");
					#endif
					return (WHILE);
				}		
	<INITIAL>do		{
					#if DBG == 1
						printf(" DO ");
					#endif
					return (DO);
				}
	<INITIAL>begin		{
					#if DBG == 1
						printf(" INICIO ");
					#endif
					return (INICIO);
				}
	<INITIAL>end		{
					#if DBG == 1
						printf(" FIM ");
					#endif
					return (FIM);
				}
	<INITIAL>to		{
					#if DBG == 1
						printf(" TO ");
					#endif
					return (TO);
				}
	<INITIAL>step		{
					#if DBG == 1
						printf(" STEP ");
					#endif
					return (STEP);
				}
	<INITIAL>downto		{
					#if DBG == 1
						printf(" DOWNTO ");
					#endif
						return (DOWNTO);
				}
	<INITIAL>procedure	{
					#if DBG == 1
						printf(" PROCEDURE ");
					#endif
						return (PROCEDURE);
				}
	<INITIAL>function	{
					#if DBG == 1
						printf(" FUNCTION ");
					#endif
					return (FUNCTION);
				}
	<INITIAL>record		{
					#if DBG == 1
						printf(" RECORD ");
					#endif
					return (RECORD);
				}
	<INITIAL>array		{
					#if DBG == 1
						printf(" ARRAY ");
					#endif
					return (ARRAY);
				}
	<INITIAL>aspect		{
					#if DBG == 1
						printf(" ASPECT ");
					#endif
						return (ASPECT);
				}
	<INITIAL>before		{
					#if DBG == 1
						printf(" BEFORE ");
					#endif
						return (BEFORE);
				}
	<INITIAL>after		{
					#if DBG == 1
						printf(" AFTER ");
					#endif
					return (AFTER);
				}
	<INITIAL>true		{
					#if DBG == 1
						printf(" TRUE ");
					#endif
					return (TRUE);
				}
	<INITIAL>false		{
					#if DBG == 1
						printf(" FALSE ");
					#endif
					return (FALSE);
				}
	<INITIAL>case		{
					#if DBG == 1
						printf(" CASE ");
					#endif
					return (CASE);
				}
	<INITIAL>boolean	{
					#if DBG == 1
						printf(" BOOLEAN ");
					#endif
						return (BOOLEAN);
				}
	<INITIAL>string		{
					#if DBG == 1
						printf(" STRING_TYPE ");
					#endif
					return (STRING_TYPE);
				}
	<INITIAL>char		{
					#if DBG == 1
						printf(" CHAR_TYPE ");
					#endif
						return (CHAR_TYPE);
				}
	<INITIAL>real		{
					#if DBG == 1
						printf(" REAL ");
					#endif
					return (REAL);
				}
	<INITIAL>integer	{
					#if DBG == 1
						printf(" INTEGER ");
					#endif
					return (INTEGER);
				}
	<INITIAL>of		{
					#if DBG == 1
						printf(" OF ");
					#endif
					return (OF);
				}
	<INITIAL>".."		{
					#if DBG == 1
						printf(" RANGE ");
					#endif
					return (RANGE);
				}
	<INITIAL>":"		{
					#if DBG == 1
						printf(" DOISPONTOS ");
					#endif
						return (DOISPONTOS);
				}
	<INITIAL>"^"		{
					#if DBG == 1
						printf("  POINTER ");
					#endif
					return (POINTER);
				}
	<INITIAL>"+"		{
					#if DBG == 1
						printf(" MAIS ");
					#endif 
					return (MAIS);
				}
	<INITIAL>"*"		{
					#if DBG == 1
						printf(" OP_ARITMETICO ");
					#endif
					yylval = criarNovoNoBasico("*",0);	
					 return (OP_ARITMETICO);
				}
	<INITIAL>"/"		{
					#if DBG == 1
						printf(" OP_ARITMETICO ");
					#endif
					yylval = criarNovoNoBasico("/",0);	
					return (OP_ARITMETICO);
				}
	<INITIAL>"%"		{
					#if DBG == 1
						printf(" OP_ARITMETICO ");
					#endif
					yylval = criarNovoNoBasico("%",0);	
					return (OP_ARITMETICO);
				}
	<INITIAL>"-"		{
					#if DBG == 1
						printf(" MENOS ");
					#endif
					yylval = criarNovoNoBasico("-",0);	
					return (MENOS);
				}
	<INITIAL>"!"		{
					#if DBG == 1
						printf(" NAO ");
					#endif
					return (NAO);
				}
	<INITIAL>":="		{
					#if DBG == 1
						printf(" ATRIBUICAO ");
					#endif
					return (ATRIBUICAO);
				}
	<INITIAL>"="		{
					#if DBG == 1
						printf(" CONST_ATRIB ");
					#endif
                    yylval = criarNovoNoBasico(" = ", 0);
					return (CONST_ATRIB);
				}
	<INITIAL>";"		{
					#if DBG == 1
						printf(" PONTOEVIRGULA ");
					#endif
					return (PONTOEVIRGULA);
				}		
	<INITIAL>"&&"		{
					#if DBG == 1
						printf(" OP_LOGICO ");
					#endif
					yylval = criarNovoNoBasico("&&",0);	
					return (OP_LOGICO);
				}		
	<INITIAL>"||"		{
					#if DBG == 1
						printf(" OP_LOGICO ");
					#endif
					yylval = criarNovoNoBasico("||",0);	
					return (OP_LOGICO);
				}		
	<INITIAL>"["		{
					#if DBG == 1
						printf(" ABRECOL ");
					#endif
					return (ABRECOL);
				}
	<INITIAL>"]"		{
					#if DBG == 1
						printf(" FECHACOL ");
					#endif
					return (FECHACOL);
				}
	<INITIAL>"("		{
					#if DBG == 1
						printf(" ABREPAR ");
					#endif
					return (ABREPAR);
				}
	<INITIAL>")"		{
					#if DBG == 1
						printf(" FECHAPAR ");
					#endif
					return (FECHAPAR);
				}
	<INITIAL>"."		{	
					#if DBG == 1
						printf(" PONTO ");
					#endif
					return (PONTO);
				}
	<INITIAL>","		{
					#if DBG == 1
						printf(" VIRGULA ");
					#endif
					return (VIRGULA);
				}			
	<INITIAL>{float} 	{
					#if DBG == 1
						printf(" FLOAT ");
					#endif
					yylval = instalar_float();
					return (FLOAT);
				}
	<INITIAL>{numero}	{
					#if DBG == 1
						printf(" NUMERO ");
					#endif
					yylval = instalar_numero(); 
					return (NUMERO);
				}
	<INITIAL>{id}		{
					#if DBG == 1
						printf(" ID ");
					#endif
					yylval = instalar_id();
					return (ID);
				}
	<INITIAL>"<"		{
					#if DBG == 1
						printf(" RELOP ");
					#endif
					yylval = criarNovoNoBasico("<",0);	
					return (RELOP);
				}
	<INITIAL>"<="		{
					#if DBG == 1
						printf(" RELOP ");
					#endif
					yylval = criarNovoNoBasico("<=",0);	 
					return (RELOP);
				}
	<INITIAL>"=="		{
					#if DBG == 1
						printf(" RELOP ");
					#endif
					yylval = criarNovoNoBasico("==",0);	
					return (RELOP);
				}
	<INITIAL>"!="		{
					#if DBG == 1
						printf(" RELOP ");
					#endif
					yylval = criarNovoNoBasico("!=",0);	
					return (RELOP);
				}
	<INITIAL>">"		{
					#if DBG == 1
						printf(" RELOP ");
					#endif
					yylval = criarNovoNoBasico(">",0);	
					return (RELOP);
				}
	<INITIAL>">="		{
					#if DBG == 1
						printf(" RELOP ");
					#endif
					yylval = criarNovoNoBasico(">=",0);	
					return (RELOP);
				}
	<INITIAL>{string}	{
					#if DBG == 1
						printf(" STRING_TERM ");
					#endif
					yylval = instalar_string();
					return (STRING_TERM);
				}
	<INITIAL>{char}		{
					#if DBG == 1
						printf(" CHAR_TERM ");
					#endif
					yylval = instalar_char(); 
					return (CHAR_TERM);
				}
	<INITIAL>"@"		{
					yyerror(" Simbolo @ nao existe neste programa");
					exit(1);
				}
	<INITIAL>.		{
					yyerror("Simbolo nao reconhecido");
					exit(1);
				}	
%%

no instalar_id(){
	no novoNo;
	novoNo = criarNovoNoBasico(yytext,0);
	return novoNo;	                  
}

no instalar_float(){
	no novoNo;
	novoNo = criarNovoNoBasico(yytext,FLOAT_V);	
	return novoNo;
}

no instalar_numero(){
	no novoNo;
	novoNo = criarNovoNoBasico(yytext,INT_V);	
	return novoNo;
}

no instalar_char(){
	no novoNo;
	novoNo = criarNovoNoBasico(yytext,CHAR_V);	
	return novoNo;
}

no instalar_string(){
	no novoNo;
	novoNo = criarNovoNoBasico(yytext,STRING_V);	
	return novoNo;
}








